# -*- coding: utf-8 -*-
# -文件说明-         控制鼠标和键盘
# @Time    : 2019/11/22 20:42
# @Author  : hwx
# @Email   : @163.com
# @File    : mousetest.py
# @Software: PyCharm
import time

from pynput.mouse import Button, Controller

mouse = Controller()


def fun1():
    # Read pointer position——获取当前鼠标指针坐标：mouse.position
    print('The current pointer position is {0}'.format(
        mouse.position))

    # Set pointer position——设置鼠标指针坐标,左上角是（0，0），右下角是（1960+，1060+）
    # mouse.position = (503, 526)   # 22.1060   20,1013  26,932
    # print('Now we have moved it to {0}'.format(
    #     mouse.position))

    # Move pointer relative to current position——移动指针到相对于当前位置
    # mouse.move(5, -5)

    # Press and release——按下，松开
    # mouse.press(Button.left)    # （按下不松开）
    # mouse.release(Button.left)

    # Double click; this is different from pressing and releasing
    # twice on Mac OSX
    # mouse.click(Button.left, 3)

    # Scroll two steps down
    # mouse.scroll(0, 2)
# fun1()


def fun2():
    i = 10
    mouse.position = (503, 526)
    print('Now we have moved it to {0}'.format(
        mouse.position))
    for j in range(i):
        time.sleep(2)
        print('j=', j)
        print('The current pointer position is {0}'.format(
            mouse.position))
        if j % 2 == 0:
            mouse.move(10 + i, -10 * j)
            mouse.click(Button.left, 3)
            print('j为偶数')
        # Move pointer relative to current position——移动指针到相对于当前位置
        else:
            mouse.move(-10 - i, 10 * j)
            mouse.click(Button.left, 3)
            print('j为奇数')
    print('循环结束')
    # mouse.scroll(0, 2)  #


# fun2()


def html_click():
    """
浏览器任务栏当前位置:(222, 1056)
按钮1当前位置:(987, 196)
按钮2当前位置:(987, 307)
按钮3当前位置:(987, 413)
pycharm任务栏当前位置:(699, 1069)
pycharm代码区当前位置:(844, 401)
    """
    print('任务栏当前位置:{0}'.format(mouse.position))
    mouse.position = (222, 1056)
    time.sleep(0.3)
    mouse.click(Button.left, 1)
    time.sleep(2)
    for i in range(10):
        mouse.position = (987, 196)
        mouse.click(Button.left, 1)

        mouse.position = (987, 307)
        mouse.click(Button.left, 1)

        mouse.position = (987, 413)
        mouse.click(Button.left, 1)
    print('点击完毕')
    mouse.position = (699, 1069)
    mouse.click(Button.left, 1)
    mouse.position = (844, 401)
    mouse.click(Button.left, 1)
    print('结束')


html_click()


def auto_close():
    """
模仿手动关机
    """
    # 22.1060   20,1013  26,932
    mouse.position = (22, 1059)
    mouse.click(Button.left, 1)
    time.sleep(2)
    mouse.position = (20, 1013)
    mouse.click(Button.left, 1)
    time.sleep(2)
    mouse.position = (26, 931)
    # mouse.click(Button.left, 1)


# auto_close()
